// 设备维修工作流数据模型

export interface Device {
  id: number;
  name: string;
  serialNumber: string;
  model: string;
  location: string;
  status: DeviceStatus;
  createdAt: Date;
  lastMaintenanceDate?: Date;
}

export interface RepairRequest {
  id: number;
  deviceId: number;
  device?: Device;
  title: string;
  description: string;
  faultDescription?: string; // 添加故障描述
  priority: RepairPriority;
  urgencyLevel?: RepairPriority; // 添加紧急程度
  status: RepairStatus;
  requestedBy: string;
  assignedTo?: string;
  createdAt: Date;
  startedAt?: Date;
  completedAt?: Date;
  workflowInstanceId?: string;
  notes?: string;
  estimatedCost?: number;
  actualCost?: number;
  requestedByUserId?: number;
  requestedByUser?: User;
  assignedToUserId?: number;
  assignedToUser?: User;
  workflowInstance?: WorkflowInstance;
  deviceModel?: string; // 添加设备型号
}

export interface User {
  id: number;
  username: string;
  fullName: string;
  name: string; // 添加 name 属性用于向后兼容
  email: string;
  phone?: string;
  role: UserRole;
  createdAt: Date;
  isActive: boolean;
  department?: string;
}

export interface ExternalVendor {
  id: number;
  companyName: string;
  contactPerson: string;
  contactPhone: string;
  contactEmail: string;
  address: string;
  notes?: string;
  createdAt: Date;
  isActive: boolean;
}

export interface WorkflowInstance {
  id: number;
  repairRequestId: number;
  repairRequest: RepairRequest;
  elsaWorkflowInstanceId: string;
  currentStep: string;
  status: WorkflowStatus;
  createdAt: Date;
  completedAt?: Date;
  createdBy?: string;
  data?: string;
  steps: WorkflowStep[];
  
  // Decision data
  isExternalRepair?: boolean;
  externalVendorId?: number;
  externalVendor?: ExternalVendor;
  
  // Repair details
  repairContent?: string;
  repairHours?: number;
  repairCost?: number;
  repairNotes?: string;
  
  // Approval data
  isApproved?: boolean;
  approvalNotes?: string;
  approvedBy?: string;
  approvedAt?: Date;
}

export interface WorkflowStep {
  id: number;
  workflowInstanceId: number;
  workflowInstance: WorkflowInstance;
  stepName: string;
  stepType: string;
  status: StepStatus;
  createdAt: Date;
  completedAt?: Date;
  completedBy?: string;
  data?: string;
  order: number;
}

export enum DeviceStatus {
  NORMAL = 'Normal',
  NEEDS_MAINTENANCE = 'NeedsMaintenance',
  UNDER_REPAIR = 'UnderRepair',
  OUT_OF_SERVICE = 'OutOfService'
}

export enum RepairPriority {
  LOW = 1,
  MEDIUM = 2,
  HIGH = 3,
  CRITICAL = 4
}

export enum RepairStatus {
  PENDING = 'Pending',
  DECISION_PENDING = 'DecisionPending',
  EXTERNAL_REPAIR = 'ExternalRepair',
  INTERNAL_REPAIR = 'InternalRepair',
  WAITING_FOR_APPROVAL = 'WaitingForApproval',
  APPROVED = 'Approved',
  IN_PROGRESS = 'InProgress',
  WAITING_FOR_PARTS = 'WaitingForParts',
  TESTING = 'Testing',
  COMPLETED = 'Completed',
  REJECTED = 'Rejected',
  CANCELLED = 'Cancelled'
}

export enum WorkflowStatus {
  RUNNING = 'Running',
  COMPLETED = 'Completed',
  CANCELLED = 'Cancelled',
  FAILED = 'Failed'
}

export enum StepStatus {
  PENDING = 'Pending',
  IN_PROGRESS = 'InProgress',
  COMPLETED = 'Completed',
  SKIPPED = 'Skipped',
  FAILED = 'Failed'
}

export enum UserRole {
  TECHNICIAN = 1,
  ADMIN = 2
}

// API Request DTOs
export interface StartWorkflowRequest {
  repairRequestId: number;
  currentUser: string;
}

export interface DecisionRequest {
  workflowInstanceId: number;
  isExternalRepair: boolean;
}

export interface ExternalVendorRequest {
  workflowInstanceId: number;
  externalVendorId: number;
}

export interface InternalRepairRequest {
  workflowInstanceId: number;
}

export interface RepairDetailsRequest {
  workflowInstanceId: number;
  repairContent: string;
  repairHours: number;
  repairCost: number;
  repairNotes?: string;
}

export interface ApprovalRequest {
  workflowInstanceId: number;
  isApproved: boolean;
  approvalNotes?: string;
  approvedBy: string;
}

// API Response DTOs
export interface WorkflowActionResponse {
  success: boolean;
  message: string;
  workflowCompleted?: boolean;
  nextStep?: string;
  workflowInstanceId?: number;
  elsaWorkflowInstanceId?: string;
}

export interface PendingTask {
  id: number;
  repairRequestId: number;
  currentStep: string;
  createdAt: Date;
  repairRequest: {
    id: number;
    title: string;
    description: string;
    priority: RepairPriority;
    status: RepairStatus;
    device: {
      name: string;
      serialNumber: string;
      location: string;
    };
  };
} 